package com.hr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hr.dao.KaoqinDao;
import com.hr.model.KaoqinModel;
import com.hr.service.KaoqinService;

@Service
public class KaoqinServiceImpl implements KaoqinService {
	@Autowired
	private KaoqinDao kaoqinDao;

	@Override
	public List<KaoqinModel> findAll() {
		return kaoqinDao.findAll();
	}

	@Override
	public List<KaoqinModel> findAll(String user_id) {
		if (user_id != null && !user_id.trim().equals("")) {
			return kaoqinDao.findAll(user_id);
		}
		return null;
	}

	@Override
	public boolean kaoqin(String type, String userId) throws Exception {
		if (type == null || "".equals(type.trim()))
			return false;
		//上班
		if ("on".equals(type)) {
			//检查今日是否已经签过到
			boolean result  = kaoqinDao.checkWorkOn(userId);
			if(result){
				return false;
			}
			kaoqinDao.workOn(userId);
		} else if ("off".equals(type)) {//下班
			kaoqinDao.workOff(userId);
		} else
			return false;
		return true;
	}
}
